We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392726 - incbin with empty string and -I switch, its length used in %rep, causes %rep error that hides other errors
Summary: incbin with empty string and -I switch, its length used in %rep, causes %rep ...
Status: OPEN
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.15.xx
Hardware: PC Linux
: Medium minor
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2020-12-14 08:02 PST by E. C. Masloch
Modified: 2020-12-14 08:03 PST (History)
5 users (show)

Obtained from: Built from git using configure
Generated by: ---
Bug category:
Observed for: ---
Regression: ---
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2020-12-14 08:02:03 PST
When passing the empty string to incbin I expect an error from incbin. However, if the "length" of the incbinned data is used in a counter of a subsequent %rep, and there is a valid -I switch with an existing directory on the NASM command line, then the %rep will receive a very large value which will cause NASM to fail with *that* error message. The problem is that the incbin error is not displayed, making it difficult to figure out the cause of the error.

Here's a few test cases:

test$ nasm -v
NASM version 2.15.03rc1 compiled on Sep 30 2020
test$ cat test.asm
label:
incbin ""
%rep $ - label
%endrep
test$ nasm test.asm
test.asm:2: error: `incbin': unable to get length of file `'
test$ nasm test.asm -I ../lmacros/
test.asm:3: error: `%rep' count 9223372036854775807 exceeds limit (currently 1000000)
test$ cat test2.asm
incbin ""
test$ nasm test2.asm
test2.asm:1: error: `incbin': unable to get length of file `'
test$ nasm test2.asm -I ../lmacros/
test2.asm:1: error: `incbin': unexpected EOF while reading file `../lmacros/'
test2.asm:1: error: `incbin': error while reading file `../lmacros/'
test$ 


I came across this error during development of my FAT FS format script called bootimg. If the generic def _PAYLOADFILE is not set on the NASM command line it receives the default value of "" (the empty string, including quote marks). Prior to the latest commit [1] this would lead to the incbin directive receiving the empty string. An -I switch is generally needed for this script because it needs the lmacros macro collection [2]. Finally, the size of the incbin's data is used to determine the loop counter of a %rep [3] exposing this NASM bug. As reported, the incbin error is not displayed by NASM in this case. Likewise, the %error directive that is meant to notify the user about the uninitialised def is also not displayed [4].


[1]: https://hg.ulukai.org/ecm/bootimg/rev/50b2a696666a
[2]: https://hg.ulukai.org/ecm/lmacros/
[3]: https://hg.ulukai.org/ecm/bootimg/file/50b2a696666a/bootimg.asm#l1298
[4]: https://hg.ulukai.org/ecm/bootimg/file/50b2a696666a/bootimg.asm#l243